import { Body, Controller, Delete, Get, Param, Patch, Post, Query, Req } from '@nestjs/common'
import { QueryListDto, ResponseListDto } from './dto'
import { isEmpty } from 'rxjs'
import { ResultData } from './response/result'
import { ApiBearerAuth } from '@nestjs/swagger'
import { CurrentUser } from 'src/app.decorator'
import { uuid } from './utils/common'

@ApiBearerAuth()
export class BaseController<T, K> {
  service = null
  constructor(service: K) {
    this.service = service
  }

  Success(data, msg){
    return ResultData.success(data, msg)
  }

  Fail(data, msg){
    return ResultData.fail(400, data, msg)
  }

  InitEntity(entity: any, @CurrentUser() user: any){
    if(entity.Id == null || entity.Id == undefined || entity.Id == ''){
      entity.Id = uuid(36).replace(/-/g, '');
    }
    entity.createBy = user.username;
    entity.updateBy = user.username;
    entity.tenantId = user.tenantId;
    entity.deleted = 0;
    return entity;
  }

  updateEntity(entity: any, @CurrentUser() user: any){
    entity.updateBy = user.username;
    return entity;
  }
}
